package com.example.treeutil.model.anno;

import com.example.treeutil.tree.NodeValue;

import java.util.ArrayList;
import java.util.List;

/**
 * 2022/12/9
 * 货品 目录 作为目录的对象，必须有 List<Object>
 * @author fengyu
 */
@NodeValue
public class Directory {
    @NodeValue(field = NodeValue.FIELD.ID)
    private String id;

    @NodeValue(field = NodeValue.FIELD.PID)
    private String pid;

    private String name;
    private int index;

    private List<Object> subs = new ArrayList<>();

    public Directory(){}
    public Directory(String id, String pid, String name, int index){
        this.id = id;
        this.pid = pid;
        this.name = name;
        this.index = index;
    }

    @NodeValue(method = NodeValue.METHOD.HAS_PARENT)
    public boolean hasParent(){
        return null != pid && pid.length() > 0;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @NodeValue(method = NodeValue.METHOD.GET_INDEX)
    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    @NodeValue(method = NodeValue.METHOD.GET_SUBS)
    public List<Object> getSubs() {
        return subs;
    }

    public void setSubs(List<Object> subs) {
        this.subs = subs;
    }

    /**
     * 可以没有这个方法，但必须有Get_Subs方法*
     * @param obj
     */
    @NodeValue(method = NodeValue.METHOD.ADD_CHILD)
    public void addChild(Object obj) {
        subs.add(obj);
    }
}
